package com.intech.android.demo.cms.beans;


import com.intech.android.demo.cms.bo.Group;
import com.intech.android.demo.cms.common.Constants;
import com.intech.android.demo.cms.common.FacesHelper;
import com.intech.android.demo.cms.common.Util;
import com.intech.android.demo.cms.decorators.AbonentsGroupDecorator;

import javax.swing.text.AbstractDocument;
import java.util.ArrayList;
import java.util.List;

public class AbonentGroupsBean extends BaseBean
{
    private List<Group> groupBOs;
    private List<AbonentsGroupDecorator> groups;
    private String information;
    private String chosenAge = "";
    private String chosenARPU = "";
    private String chosenSex = "";


    public String showGroupInformation()
    {
        String name = FacesHelper.getParameter("name");
        for (Group group : groupBOs)
        {
            String groupName = group.getName();
            if (groupName.equalsIgnoreCase(name))
            {
                chosenAge = getAge(group.getAge());
                chosenARPU = getARPU(group.getARPU());
                chosenSex = getSex(group.getSex());
            }
        }

        return Constants.Navigation.ABONENET_GROUP_INFORMATION_LINK;
    }


    private String getARPU(String arpu)
    {
        String ageDescription = " ARPU ";

        if (arpu.equals("low"))
        {
            return ageDescription += "0-8$";
        }
        if (arpu.equals("med"))
        {
            return ageDescription += "8-15$";
        }
        if (arpu.equals("hi"))
        {
            return ageDescription += "15-30$";
        }
        return ageDescription += "more 30$";
    }

    private String getAge(String age)
    {
        String ageDescription = " Age ";
        if (age.equals("1518"))
        {
            return ageDescription += "15-18";
        }
        if (age.equals("1921"))
        {
            return ageDescription += "19-21";
        }
        if (age.equals("2227"))
        {
            return ageDescription += "22-27";
        }
        if (age.equals("2835"))
        {
            return ageDescription += "28-35";
        }
        if (age.equals("3645"))
        {
            return ageDescription += "46-45";
        }
        return ageDescription += "45";
    }

    private String getSex(String sex)
    {
        if (sex.equals("M"))
        {
            return "Man";
        }
        return "Women";
    }


    public String getChosenAge()
    {
        return chosenAge;
    }

    public void setChosenAge(String chosenAge)
    {
        this.chosenAge = chosenAge;
    }

    public String getChosenARPU()
    {
        return chosenARPU;
    }

    public void setChosenARPU(String chosenARPU)
    {
        this.chosenARPU = chosenARPU;
    }

    public String getChosenSex()
    {
        return chosenSex;
    }

    public void setChosenSex(String chosenSex)
    {
        this.chosenSex = chosenSex;
    }

    public String toAbonentsGroups()
    {
        return Constants.Navigation.ABONENT_GROUPS_LINK;
    }

    public List<Group> getGroupBOs()
    {
        if (Util.isEmpty(groupBOs))
        {
            groupBOs = getGroupDAO().getAll();
        }
        return groupBOs;
    }

    public void setGroupBOs(List<Group> groupBOs)
    {
        this.groupBOs = groupBOs;
    }

    public List<AbonentsGroupDecorator> getGroups()
    {
        if (Util.isEmpty(groups))
        {
            groups = new ArrayList<AbonentsGroupDecorator>();
            for (int i = 0; i < getGroupBOs().size() / 8; i++)
            {
                List<Group> rowGroupsArray = new ArrayList<Group>();
                for (int j = 0; j < 8; j++)
                {
                    rowGroupsArray.add(getGroupBOs().get(j + i * 8));
                }
                groups.add(new AbonentsGroupDecorator(rowGroupsArray));
            }
        }
        return groups;
    }

    public void setGroups(List<AbonentsGroupDecorator> groups)
    {
        this.groups = groups;
    }

    public String getInformation()
    {

        return information;
    }

    public void setInformation(String information)
    {
        this.information = information;
    }
}
